#include "stdafx.h"
#include "DepthStencilState.h"

namespace Reign
{namespace Video
{namespace D3D10
{
	#pragma region Constructors
	DepthStencilState::DepthStencilState(DisposableI^ parent, DepthStencilStateDescI^ desc)
	: Disposable(parent)
	{
		null();
		try
		{
			video = parent->FindParentOrSelfWithException<Video^>();

			ID3D10DepthStencilState* depthStencilStateTEMP;
			DepthStencilStateDesc^ descTEMP = (DepthStencilStateDesc^)desc;
			if (FAILED(video->Device->CreateDepthStencilState(descTEMP->Desc, &depthStencilStateTEMP)))
			{
				Debug::ThrowError(L"DepthStencilState", L"Failed to create DepthStencilState");
			}
			depthStencilState = depthStencilStateTEMP;
		}
		catch (Exception^ ex)
		{
			delete this;
			throw ex;
		}
	}

	DepthStencilState::~DepthStencilState()
	{
		disposeChilderen();
		if (depthStencilState) depthStencilState->Release();
		null();
	}

	void DepthStencilState::null()
	{
		depthStencilState = 0;
	}
	#pragma endregion
	
	#pragma region Methods
	void DepthStencilState::Enable()
	{
		video->Device->OMSetDepthStencilState(depthStencilState, 0);
	}
	#pragma endregion
}
}
}